#!/usr/bin/env python
"""
	寻找最多元素
"""
__author__ = "lynn.lin"

def majority(A):
    length = len(A)
    value = a[length/2]
    count = 0
    for v in range(0,length):
        if A[v] == value:
            count += 1
    if count > length/2 :
        return value
    else :
        return None


def candiate(m,A,length):
	j = m
	c = A[m]
	count = 1
	while ( j < length -1 and count > 0 ) :
		j = j + 1
		if A[j] == c :
			count += 1
		else :
			count -= 1
	if j == length-1 :
		return c
	else :
		return candiate(j+1,A,length)

def majority_2(A):
	length = len(A)
	c = candiate(0,A,length)
	count = 0
	for j in range(0,length):
		if A[j] == c :
			count += 1
	if count > length/2 :
		return c
	else :
		return None

if __name__ == '__main__':
    A = [1,3,2,3,3,4,3]
    out = majority_2(A)
    print out
